<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="vn.fpt.fsoft.entity.User" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Retrieve Password</title>
<link rel="stylesheet" href="css/loginstyle.css" type="text/css">
<script type="text/javascript" src="js/jquery-latest.js"></script>

<script type="text/javascript">
	function validate() {
		if (document.getElementById("username").value == "") {
			document.getElementById("error").innerHTML = "Please enter the Username.";
			document.getElementById("username").focus();
			return false;
		}
		if (document.getElementById("email").value == "") {
			document.getElementById("error").innerHTML = "Please enter the Email.";
			document.getElementById("email").focus();
			return false;
		}
		if(validateEmail(document.getElementById("email").value) == false){
			document.getElementById("error").innerHTML = "Please enter correct email.";
			document.getElementById("email").focus();
			return false;
		}
		return true;
	}
	
	/*Validate Email*/
	function validateEmail(email) { 
		var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
		return re.test(email);
	}
	
	function retrieve(){
		if(validate()) {
			var username = document.getElementById("username").value;
			var email = document.getElementById("email").value;
			$.ajax({
				url : "UserController?action=retrieve&username="+ username
						+ "&email="+ email,
				type : "POST",
				success : function(data) {
					document.getElementById("error").innerHTML = data;
				},
				error : function(data) {
					alert("fail");
				}
			});
		}
	}

</script>
</head>
<body>
	<div class="container">
	<div class="login">
		<h1>Retrieve Password</h1>
		<p>Input correct username and email, a new password will be sent to your mail.</p>
		<div id="retrieve">
			<p><input type="text" id="username" value="" placeholder="Username"></p>
			<p><input type="text" id="email" value="" placeholder="Email"></p>
			<p id="error"></p>
			<p class="submit"><input type="submit" name="commit" value="Retrieve Password" onclick="retrieve();"></p>
		</div>
	</div>
	</div>
</body>
</html>